package com.example.study.student.controller;

import com.example.study.basic.exception.BasicCode;
import com.example.study.basic.exception.BasicException;
import com.example.study.basic.model.ResultModel;
import com.example.study.basic.util.LoggerUtil;
import com.example.study.student.entity.Student;
import com.example.study.student.service.StudentServiceImpl;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author nannan
 */
@RestController
@RequestMapping("/student")
@RequiredArgsConstructor
public class StudentController {

    @NonNull
    private final StudentServiceImpl studentService;

    @GetMapping("/select")
    public ResponseEntity getStudent() {
        List<Student> studentList = studentService.selectStudentList();
        LoggerUtil.info("学生列表信息",studentList.toString());
        return ResponseEntity.ok(ResultModel.ok(studentList));
    }

    @PostMapping("/insert")
    public ResponseEntity insertStudent(@RequestBody Student student) throws BasicException {
        if (1 == 1) {
            int i = 1/0;
        }
        return ResponseEntity.ok(true);
    }
}
